package com.guizi.halftimesroom.frament;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.guizi.halftimesroom.R;
import com.guizi.halftimesroom.adapter.DiscoverAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoverFragment extends Fragment {

    @InjectView(R.id.discover_tl)
    TabLayout mDiscoverTl;
    @InjectView(R.id.discover_search_icon)
    ImageView MdiscoverSearchIcon;
    @InjectView(R.id.vp_discover)
    ViewPager mVpDiscover;
    private List<Fragment> fragmentList;
    private String[] titles={"推荐","绘画","写作","COS"};

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        fragmentList= new ArrayList<>();
        fragmentList.add(new DiscoverRecommandFragment());
        fragmentList.add(new DiscoverIllustFragment());
        fragmentList.add(new DiscoverNovelFragment());
        fragmentList.add(new DiscoverCosFragment());

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_fragmentdiscover, container, false);
        ButterKnife.inject(this, view);
        return view;
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mVpDiscover.setAdapter(new DiscoverAdapter(getChildFragmentManager(),fragmentList));
        mVpDiscover.setOffscreenPageLimit(3);
        mDiscoverTl.setupWithViewPager(mVpDiscover);
        for (int i = 0; i <mDiscoverTl.getTabCount() ; i++) {
            mDiscoverTl.getTabAt(i).setText(titles[i]);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
